
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}


var oid = getQueryString("oid");
if(oid != null) {
	
	$.ajax({
		cache:true,
		type:"GET",
		url:"/dingcan/dingcan/getByIdFood.do?oid=" + oid,
		async:true,
		error:function(data) {
			alert("error");
		},
		success:function(data) {
			
			var result = $.parseJSON(data).result[0];
			var pics = result.pics;
			//img
			$("#showimg").attr("src",pics[0]);
			var smallpic = $(".smallpic");
			
			var html = "";
			for(var i = 0; i < pics.length; i++) {
				html += '<li><img src="upload/02.jpg" onmouseover="show(this)" onmouseout="hide()"></li>';
			}
			smallpic.empty();
			smallpic.html(html);
			
			//foodnameFreight
			var foodName_a = $(".foodname_a");
			html = "<h1>"+ result.foodName + "</h1>";
			foodName_a.empty();
			foodName_a.html(html);
			
			//foodPrice
			var price01 = $(".price01 span");
			html = result.foodPrice;
			price01.empty();
			price01.html(html);
			
			//peisongfei
			var freight = $(".Freight");
			html = "<span>配送费用：</span>  <span> "+result.yunfei+" RMB</span>"
			freight.empty();
			freight.html(html);
			
			//form
			$("#oid").attr("value", result.oid);
			
			var cont_padding = $(".cont_padding");
			 
			html =  '<img src="'+ pics[0] +'">' + 
		       		'<p>'+ result.description.replace(/\\r\\n/g, "<br/>") +'</p>' ;
		    cont_padding.html(html);
		}
	}); 

};


function toCard() {
	$.ajax({
		cache:false,
		type:"POST",
		url:"/dingcan/dingcan/addCard.do",
		data:$("#addToCard").serialize(),
		async:true,
		error:function(data) {
			alert("失败！" + data);
		},
		success:function(data) {
			var json = $.parseJSON(data);
			if(json.success == true) {
				alert("加入购物车成功");
			}
			
			changeCart();
		}
	});
};


    